package org.jeecg.modules.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.content.entity.JcContent;
import org.jeecg.modules.content.mapper.JcContentMapper;
import org.jeecg.modules.content.service.IJcContentService;
import org.jeecg.modules.utils.PojoConvertUtil;
import org.jeecg.modules.website.entity.JcChannel;
import org.jeecg.modules.website.vo.JcChannelVo;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: jc_content
 * @Author: jeecg-boot
 * @Date:   2020-06-22
 * @Version: V1.0
 */
@Service
public class JcContentServiceImpl extends ServiceImpl<JcContentMapper, JcContent> implements IJcContentService {
    public List<JcChannel> getContentsByChannelForHome(List<JcChannel> jcChannels,int pageSize){
       // List<JcChannel> jcChannelVos= PojoConvertUtil.convertPojos(jcChannels,JcChannelVo.class);
        for (int i = 0;jcChannels!=null && i < jcChannels.size(); i++) {
            jcChannels.get(i).getId();
            QueryWrapper<JcContent> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("channel_code",jcChannels.get(i).getChannelCode());
            queryWrapper.orderByDesc("release_date").orderByAsc("sequence");
            Page<JcContent> page = new Page<JcContent>(1, pageSize);
            IPage<JcContent> ip= page(page, queryWrapper);
            jcChannels.get(i).setContentList(ip.getRecords());
        }
        return jcChannels;
    }

    @Override
    public IPage fullTextSearch(String channelName,int current,int pageSize) {

        Page<JcContent> page = new Page<JcContent>(1, pageSize);
      //  IPage<JcContent> ip= this.
        return null;
    }
}
